﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Entity;
using BLL;
using BLL.Access;
using Platform.Http;
using Web.Class;
using Platform.Common;
using DevExpress.Web;
using System.Text;
using System.Data;

namespace Web.Controls.LAIHAN
{
    public partial class UCLHJiHuaZYLCCZ : System.Web.UI.UserControl
    {
        #region 属性
        public int FocusIndexGV
        {
            get { return Convert.ToInt32(ViewState["RowIndex"] == null ? "-1" : ViewState["RowIndex"]); }
            set { ViewState["RowIndex"] = value; }
        }

        private int _LAIHANLCZT;
        /// <summary>
        /// 来函流程编号
        /// </summary>
        public int LAIHANLCZT
        {
            get { return _LAIHANLCZT; }
            set { _LAIHANLCZT = value; }
        }
        #endregion

        #region 变量
        /// <summary>
        /// 来函用户信息
        /// </summary>
        YS_LH_YONGHUXXProcess bllLaiHanYHXX = new YS_LH_YONGHUXXProcess();
        /// <summary>
        /// 来函信息
        /// </summary>
        YS_LH_LAIHANXXProcess bllLaiHanxx = new YS_LH_LAIHANXXProcess();
        /// <summary>
        /// 计划转移信息
        /// </summary>
        YS_LH_JIHUAZYProcess bllJiHuanZYxx = new YS_LH_JIHUAZYProcess();
        /// <summary>
        /// 数据库访问
        /// </summary>
        SpHelper _sphelper = new SpHelper();
        /// <summary>
        /// 管理块
        /// </summary>
        YS_JX_GUANLIKBLL glkbll = new YS_JX_GUANLIKBLL();
        /// <summary>
        /// 用户信息
        /// </summary>
        YS_YG_YONGHUXXBLL bllyhxx = new YS_YG_YONGHUXXBLL();

        /// <summary>
        /// 流程
        /// </summary>
        YS_LH_LAIHANLCJLBLL lcbll = new YS_LH_LAIHANLCJLBLL();
        #endregion

        #region 事件
        /// <summary>
        /// 页面加载
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitControl();
            }
        }
        /// <summary>
        /// 绑定gv
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnActPerform_Click(object sender, EventArgs e)
        {
            if (C_GuanLiK.SelectedIndex == 0 && !HiddenList.Contains("h_glk"))
            {
                HiddenList.Set("h_glk", C_GuanLiK.Value);
            }
            BindGV();
        }
        /// <summary>
        /// 绑定用户信息和计划信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void BtnLeftContent_Click(object sender, EventArgs e)
        {
            BindUserInfo();
        }
        /// <summary>
        /// ajax
        /// </summary>
        /// <param name="source"></param>
        /// <param name="e"></param>
        protected void ASPxCallback1_Callback(object source, DevExpress.Web.CallbackEventArgs e)
        {
            if (e.Parameter == "queren")
            {
                //确定修改信息验证
                e.Result = e.Parameter + "|"+ReturnError();
            }
            if (e.Parameter == "querentj")
            {
                //确定按钮保存
                e.Result = e.Parameter + "|" + InsertJiHuanZY(0);
            }
            if (e.Parameter == "tijiao")
            {
                //提交选中信息
                e.Result = e.Parameter + "|" + TiJiaoXX(0);
            }
        }
        /// <summary>
        /// 绑定值
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void BtnBind_Click(object sender, EventArgs e)
        {
            BindGV();
        }
        /// <summary>
        /// 确认按钮操作
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void BtnQR_Click(object sender, EventArgs e)
        {
            //InsertJiHuanZY(0);
            XIUGAIBtn(false);
            if (gvLH.VisibleRowCount > 0)
            {
                FocusIndexGV = gvLH.FocusedRowIndex;
            }
            BindGV();
            
        }
        /// <summary>
        /// 修改按钮操作
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void BtnXG_Click(object sender, EventArgs e)
        {
            XIUGAIBtn(true);
            
        }
        /// <summary>
        /// 提交按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void BtnTJ_Click(object sender, EventArgs e)
        {
            //QueDingTJ();
            string msg=TiJiaoXX(1);
            ScriptManager.RegisterStartupScript(this, this.GetType(), "aa", "alert('操作成功');parent.layer.closeAll();", true);
        }
        /// <summary>
        /// 已确认的来函显示背景为绿色，未确认的为默认颜色
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvLH_HtmlRowPrepared(object sender, ASPxGridViewTableRowEventArgs e)
        {
            if (e.RowType != DevExpress.Web.GridViewRowType.Data) return;

            int s = Convert.ToInt32(e.GetValue("ZHUANYIQR"));

            if (s > 0)

                e.Row.BackColor = System.Drawing.Color.LightGreen;
        }
        #endregion

        #region 方法
        /// <summary>
        /// 验证提交表单
        /// </summary>
        /// <returns></returns>
        private string ReturnError()
        {
            if (txtLY.Value == null || txtLY.Value.ToString().Trim().Length == 0)
            {
                return "-1|来函内容不能为空";               
            }
            if (txtLiuChengYJ.Text.Trim().Length == 0)
            {
                return "-1|"+SetTitle() + "不能为空";
               
            }
            if (!CheckValueTJ())
            {
                
                return "-1|转移计划水量输入错误";
            }
            if (!CheckJiHuanXX())
            {
                return "-2|转移计划水量不能大于原计划水量";
                
            }
            return "1|验证通过";
        }
      
        private string TiJiaoXX(int type)
        {
            string cid = "";
            //string retstr = "";
            string laihanbh = "";
            string yonghuhs = "";
            int IsQueRen = 0;
            for (int i = 0; i < gvLH.VisibleRowCount; i++)
            {
                CheckBox ck = (CheckBox)gvLH.FindRowCellTemplateControl(i, (GridViewDataColumn)gvLH.Columns[0], "cid");
                HiddenField hid = (HiddenField)gvLH.FindRowCellTemplateControl(i, (GridViewDataColumn)gvLH.Columns[0], "id");
                HiddenField laihan = (HiddenField)gvLH.FindRowCellTemplateControl(i, (GridViewDataColumn)gvLH.Columns[0], "laihanbh");
                HiddenField yonghuh = (HiddenField)gvLH.FindRowCellTemplateControl(i, (GridViewDataColumn)gvLH.Columns[0], "yonghuh");
                HiddenField QueRen = (HiddenField)gvLH.FindRowCellTemplateControl(i, (GridViewDataColumn)gvLH.Columns[0], "ZHUANYIQR");

                if (ck.Checked && Convert.ToInt32(QueRen.Value)>0)
                {
                    cid += hid.Value + ",";
                    laihanbh += laihan.Value + ",";
                    yonghuhs += yonghuh.Value + ",";
                    //IsQueRen += Convert.ToInt32(QueRen.Value);
                }
            }
            if (cid.Trim().Length == 0&&type==0)
            {
                return "-1|请选择来函信息";
            }
            if (IsQueRen > 0)
            {
                //return;
            }
            cid = cid.Remove(cid.LastIndexOf(','));
            laihanbh = laihanbh.Remove(laihanbh.LastIndexOf(','));
            //判断来函是否已输入本步骤相关信息
            string[] arr = laihanbh.Split(',');
            for (int i = 0; i < arr.Length; i++)
            {
                if (arr[i].Trim().Length > 0)
                {
                    int? count = 0;
                    _sphelper.P_YS_LH_JIHUAZYCHECK(arr[i], this.LAIHANLCZT,out count);
                    if (count == 0&&type==0)
                    {
                        return "-1|来函编号"+arr[i]+"未输入确认计划信息";
                    }
                }
            }
            if (type == 0)
            {
                return "1|验证通过";
            }
            if (laihanbh.Trim().Length > 0)
            {
                int? NextLCZT = 0;
                string NextLCMC = "";
                //获取下个流程编号
                _sphelper.P_YS_LH_LIUCHENGPZ_LHLX(3, this.LAIHANLCZT, out NextLCZT, out NextLCMC);
               //如果不是最终流程步骤
                if (NextLCZT != null && NextLCZT >= 0)
                {
                    //更新选中的来函到下个流程步骤
                    string col = " I_LIUCHENGBH=" + NextLCZT + ",S_CAOZUOR='" + LoginInfo.CurrentUser.UserID.ToString() + "',D_CAOZUOSJ=sysdate ";
                    string where = "ID in (" + cid + ") ";
                    int succcess = bllLaiHanxx.UpdateYS_LH_LAIHANXXesDynamic(col, where);
                    
                    //更新选中的来函下一步处理人
                    for (int i = 0; i < arr.Length; i++)
                    {
                        if (arr[i].Trim().Length > 0)
                        {
                            //更新当前步骤结束时间,操作人
                            lcbll.UpdateYS_LH_LAIHANLCJLsDynamic(string.Format("D_ENDDATE=sysdate,I_CAOZUOR={0},D_CAOZUORQ=sysdate", LoginInfo.CurrentUser.UserID), " I_JLZT=0 AND I_LIUCHENGBH=" + this.LAIHANLCZT + " and S_LAIHANBH='" + arr[i].Trim() + "'");

                            //更新待处理操作人
                            int? state = -1;
                            string msg = null;
                            DataTable laihanxx = bllLaiHanxx.SelectYS_LH_LAIHANXXesDynamic("I_JLZT=0 AND S_LAIHANBH='" + arr[i].Trim() + "'", "", null);
                            _sphelper.P_YSLH_DAICHULCZR(arr[i].Trim(), 3, this.LAIHANLCZT, 0, laihanxx.Rows[0]["S_YONGHUBH"].ToString(), out NextLCZT, out NextLCMC, out state, out msg);
                            if (state < 0)
                            {
                                throw new Exception(msg);
                            }
                            if (NextLCZT != null && NextLCZT > 0)
                            {
                                ///添加流程记录信息
                                YS_LH_LAIHANLCJL lcjl = new YS_LH_LAIHANLCJL();
                                lcjl.D_CAOZUORQ = DateTime.Now;
                                lcjl.D_STARTDATE = DateTime.Now;
                                lcjl.I_CAOZUOR = LoginInfo.CurrentUser.UserID;
                                lcjl.I_LAIHANLX = 3;
                                lcjl.I_LIUCHENGBH = NextLCZT;
                                lcjl.ID = 0;

                                DataTable lcxx = lcbll.SelectYS_LH_LAIHANLCJLsDynamic(string.Format(" S_LAIHANBH={0} and I_LIUCHENGBH={1} and i_jlzt=0 ", arr[i], NextLCZT), "", null);
                                if (lcxx != null && lcxx.Rows.Count > 0)
                                {
                                    lcjl.ID = Convert.ToInt32(lcxx.Rows[0]["ID"]);
                                }
                                lcjl.S_LAIHANBH = arr[i].Trim();
                                lcjl.S_LIUCHENGMC = NextLCMC;
                                lcbll.InsertOrUpdate(lcjl);
                            }
                        }
                    }
                }
                else//如果是最终流程步骤
                {
                    //更新选中来函为审批通过
                    string col = " I_LIUCHENGZT=1,S_CAOZUOR='" + LoginInfo.CurrentUser.UserID + "',D_CAOZUOSJ=sysdate ";
                    string where = "ID in (" + cid + ") ";
                    int succcess = bllLaiHanxx.UpdateYS_LH_LAIHANXXesDynamic(col, where);

                    //string []ids=cid.Split(',');
                    for (int i = 0; i < arr.Length; i++)
                    {
                        if (arr[i].Trim().Length > 0)
                        {
                            //更新当前步骤结束时间,操作人
                            lcbll.UpdateYS_LH_LAIHANLCJLsDynamic(string.Format("D_ENDDATE=sysdate,I_CAOZUOR={0},D_CAOZUORQ=sysdate", LoginInfo.CurrentUser.UserID), " I_LIUCHENGBH=" + this.LAIHANLCZT + " and S_LAIHANBH='" + arr[i].Trim() + "'");

                            //更新待处理操作人
                            int? state = -1;
                            string msg = null;
                            DataTable laihanxx = bllLaiHanxx.SelectYS_LH_LAIHANXXesDynamic("I_JLZT=0 AND S_LAIHANBH='" + arr[i].Trim() + "'", "", null);
                            _sphelper.P_YSLH_DAICHULCZR(arr[i].Trim(), 3, this.LAIHANLCZT, 0, laihanxx.Rows[0]["S_YONGHUBH"].ToString(), out NextLCZT, out NextLCMC, out state, out msg);
                            if (state < 0)
                            {
                                throw new Exception(msg);
                            }
                            if(NextLCZT != null && NextLCZT == 0)
                            {
                                where = string.Format("S_LAIHANBH='{0}' and i_jlzt=0 ", arr[i]);
                                //查询来函相关计划转移附表信息
                                DataTable dt = bllJiHuanZYxx.SelectYS_LH_JIHUAZiesDynamic(where, "", null);
                                if (dt != null && dt.Rows.Count > 0)
                                {
                                    DataRow dr = dt.Rows[0];
                                    //_sphelper.P_YS_LH_YONGHUXXBF(dr["S_YONGHUBHJ"].ToString(), arr[i],3);
                                    //_sphelper.P_YS_LH_YONGHUXXBF(dr["S_YONGHUBHY"].ToString(), arr[i], 3);
                                    //备份修改前的信息，修改当前修改信息
                                    UpdateYS_JH_TiaoZhengJH(dr["S_LAIHANBH"].ToString(), Convert.ToInt32(dr["I_Y"]), dr["S_YONGHUBHJ"].ToString(), dr["S_YongHuBHY"].ToString());
                                }
                            }
                        }
                    }
                }

            }
            BindGV();
            return "操作成功";
        }
        /// <summary>
        /// 更新用户信息
        /// </summary>
        /// <param name="laihanbh"></param>
        private void UpdateYS_YG_YONGHUXX(string laihanbh)
        {
            DataTable oldyh = bllLaiHanYHXX.SelectYS_LH_YONGHUXXesDynamic(string.Format(" I_JLZT=0 and S_LAIHANBH='{0}'", laihanbh), "", null);
            if (oldyh != null && oldyh.Rows.Count > 0)
            {
                DataRow dr = oldyh.Rows[0];
                string col = "S_LIANXIDH='{0}',S_LIANXIR='{1}',S_YONGHUM='{2}',S_YOUBIAN='{3}',S_LIANXIBM='{4}',S_DIZHI='{5}' ";

                string where = "S_YONGHUH='{0}' and i_jlzt=0  ";
                col = string.Format(col, dr["S_LIANXIDH"], dr["S_LIANXIR"], dr["S_YONGHUM"], dr["S_YOUBIAN"], dr["S_LIANXIBM"], dr["S_DIZHI"]);
                where = string.Format(where, dr["S_YONGHUBH"]);
                bllyhxx.UpdateYS_YG_YONGHUXXesDynamic(col, where);
            }
        }
        /// <summary>
        /// 审核通过更新调整计划表
        /// </summary>
        /// <param name="laihanbh"></param>
        /// <param name="y"></param>
        /// <param name="yonghuhj"></param>
        /// <param name="yonghuhy"></param>
        private void UpdateYS_JH_TiaoZhengJH(string laihanbh,int y,string yonghuhj,string yonghuhy)
        {
            int? error = 0;
            _sphelper.P_YS_LH_BEIFENJHXX(laihanbh,yonghuhj,out error);
            _sphelper.P_YS_LH_BEIFENJHXX(laihanbh, yonghuhy, out error);
            _sphelper.P_YS_LH_JIHUAZYTZJHGX(laihanbh, y, yonghuhj, yonghuhy);
        }

        private void UpdateLY()
        {
            string col = string.Format("S_SHENQINGLY='{0}',S_CAOZUOR='{1}',D_CAOZUOSJ=sysdate ", txtLY.Value, LoginInfo.CurrentUser.UserID.ToString());
            string where = "S_LAIHANBH='{0}' ";
            where = string.Format(where, HiddenList.Get("laihanbh").ToString());

            bllLaiHanxx.UpdateYS_LH_LAIHANXXesDynamic(col, where);
        }
        /// <summary>
        /// 插入计划转移信息
        /// </summary>
        /// <param name="type"></param>
        private string InsertJiHuanZY(int type)
        {
            if (txtLY.Value == null || txtLY.Value.ToString().Trim().Length == 0)
            {
                PageTools.AlertMsg(this, "来函内容不能为空");
                return "-1|来函内容不能为空";
            }
            if (txtLiuChengYJ.Text.Trim().Length == 0)
            {
                PageTools.AlertMsg(this, SetTitle() + "不能为空");
                return "-2|" + SetTitle() + "不能为空";
            }
            if (!CheckValueTJ())
            {
                PageTools.AlertMsg(this, "转移计划水量输入错误");
                return "-3|转移计划水量输入错误";
            }
            int m1 = Convert.ToInt32(txtZYJH1.Text);
            int m2 = Convert.ToInt32(txtZYJH2.Text);
            int m3 = Convert.ToInt32(txtZYJH3.Text);
            int m4 = Convert.ToInt32(txtZYJH4.Text);
            int m5 = Convert.ToInt32(txtZYJH5.Text);
            int m6 = Convert.ToInt32(txtZYJH6.Text);
            int m7 = Convert.ToInt32(txtZYJH7.Text);
            int m8 = Convert.ToInt32(txtZYJH8.Text);
            int m9 = Convert.ToInt32(txtZYJH9.Text);
            int m10 = Convert.ToInt32(txtZYJH10.Text);
            int m11 = Convert.ToInt32(txtZYJH11.Text);
            int m12 = Convert.ToInt32(txtZYJH12.Text);
             YS_LH_JIHUAZY JiHuaZY = new YS_LH_JIHUAZY();
             JiHuaZY.D_CAOZUOR = LoginInfo.CurrentUser.UserID.ToString();
             JiHuaZY.D_CAOZUORQ = DateTime.Now;
             JiHuaZY.D_SHURURQ = DateTime.Now;
             JiHuaZY.I_JLZT = 0;
             JiHuaZY.I_LIUCHENGBH = this.LAIHANLCZT;
             JiHuaZY.I_M1 = m1;
             JiHuaZY.I_M2 = m2;
             JiHuaZY.I_M3 = m3;
             JiHuaZY.I_M4 = m4;
             JiHuaZY.I_M5 = m5;

             JiHuaZY.I_M6 = m6;
             JiHuaZY.I_M7 = m7;
             JiHuaZY.I_M8 = m8;
             JiHuaZY.I_M9 = m9;
             JiHuaZY.I_M10 = m10;

             JiHuaZY.I_M11 = m11;
             JiHuaZY.I_M12 = m12;

             JiHuaZY.I_Y = Convert.ToInt32(HiddenList.Get("Y").ToString());

             JiHuaZY.ID = 0;
             string where1 = string.Format(" ID={0} ", HiddenList.Get("laihanid").ToString());
             DataTable LaiHanxx = bllLaiHanxx.SelectYS_LH_LAIHANXXesDynamic(where1, "", null);

             if (LaiHanxx == null || LaiHanxx.Rows.Count == 0)
             {
                 return "-1|操作失败";
             }
             JiHuaZY.S_GUANLIKBH = LaiHanxx.Rows[0]["s_guanlikbh"].ToString();
             JiHuaZY.S_LAIHANBH = HiddenList.Get("laihanbh").ToString();
             JiHuaZY.S_SHENPIYJ = txtLiuChengYJ.Text;
             JiHuaZY.S_YONGHUBHJ = HiddenList.Get("YHHJ").ToString();
             JiHuaZY.S_YONGHUBHY = HiddenList.Get("YHHY").ToString();
             JiHuaZY.S_ZHANDIANBH = HiddenList.Get("ZHANDIAN").ToString();
             string where = " S_LAIHANBH='{0}' and S_YONGHUBHJ='{1}' and S_YONGHUBHY='{2}' and I_LIUCHENGBH={3} and i_jlzt=0";
             where = string.Format(where,JiHuaZY.S_LAIHANBH,JiHuaZY.S_YONGHUBHJ,JiHuaZY.S_YONGHUBHY,this.LAIHANLCZT);
             DataTable dt = bllJiHuanZYxx.SelectYS_LH_JIHUAZiesDynamic(where,"",null);
             if (dt != null && dt.Rows.Count > 0)
             {
                 JiHuaZY.ID = Convert.ToInt32(dt.Rows[0]["ID"]);
             }
             bllJiHuanZYxx.InsertOrUpdate(JiHuaZY);
             UpdateLY();
             if (type == 0)
             {
                 ///PageTools.AlertMsg(this, "操作成功");
             }
             return "1|操作成功";
            
        }
        /// <summary>
        /// 验证输入水量
        /// </summary>
        /// <returns></returns>
        private bool CheckValueTJ()
        {
            int i = 0;
            if (!int.TryParse(txtZYJH1.Text, out i))
            {
                return false;
            }
            if (!int.TryParse(txtZYJH2.Text, out i))
            {
                return false;
            }
            if (!int.TryParse(txtZYJH3.Text, out i))
            {
                return false;
            }
            if (!int.TryParse(txtZYJH4.Text, out i))
            {
                return false;
            }
            if (!int.TryParse(txtZYJH5.Text, out i))
            {
                return false;
            }
            if (!int.TryParse(txtZYJH6.Text, out i))
            {
                return false;
            }
            if (!int.TryParse(txtZYJH7.Text, out i))
            {
                return false;
            }
            if (!int.TryParse(txtZYJH8.Text, out i))
            {
                return false;
            }
            if (!int.TryParse(txtZYJH9.Text, out i))
            {
                return false;
            }
            if (!int.TryParse(txtZYJH10.Text, out i))
            {
                return false;
            }
            if (!int.TryParse(txtZYJH11.Text, out i))
            {
                return false;
            }
            if (!int.TryParse(txtZYJH12.Text, out i))
            {
                return false;
            }
            return true;
        }
        /// <summary>
        /// 设置页面标题
        /// </summary>
        private string SetTitle()
        {
            string YiJian = "";
            switch (this.LAIHANLCZT)
            {
                case 30:
                    Span_Title.InnerText = "承办人意见";
                    td_LiuChengYJ.InnerText = "承办人意见：";
                    td_LiuChengMC.InnerText = "承办人建议量：";
                    YiJian = "承办人意见";
                    break;
                case 40:
                    Span_Title.InnerText = "主任复核";
                    td_LiuChengYJ.InnerText = "主任意见：";
                    td_LiuChengMC.InnerText = "主任复核量：";
                    YiJian = "主任意见";
                    break;
                case 50:
                    Span_Title.InnerText = "节水科长审核";
                    td_LiuChengYJ.InnerText = "节水科意见：";
                    td_LiuChengMC.InnerText = "节水科审核量：";
                    YiJian = "节水科意见";
                    break;
                case 60:
                    Span_Title.InnerText = "计财科长复审";
                    td_LiuChengYJ.InnerText = "计财科意见：";
                    td_LiuChengMC.InnerText = "计财科复审量：";
                    YiJian = "计财科意见";
                    break;
                case 70:
                    Span_Title.InnerText = "处长审批";
                     td_LiuChengYJ.InnerText = "处长意见：";
                    td_LiuChengMC.InnerText = "处长审批量：";
                    YiJian = "处长意见";
                    break;
            }
            return YiJian;
        }
        /// <summary>
        /// 初始化加载
        /// </summary>
        private void InitControl()
        {
            SetTitle();
            SetDisplay();
            DataTable dtZhandian = BusinessTool.GetTextAndValue("view_as_userinfo", "ZHANDIANMC", "ZHANDIANBH", null, string.Format("USERID={0}", LoginInfo.CurrentUser.UserID)).Tables[0];
            string zhandianBH = "";
            if (dtZhandian != null && dtZhandian.Rows.Count > 0)
            {
                zhandianBH = dtZhandian.Rows[0]["VALUE"].ToString();
            }
            if (zhandianBH == "")
            {
                zhandianBH = "51";               
            }
            h_zhandian.Value = zhandianBH;
            PageTools.LoadCombox(C_YwWuY, PageTools.eLoadType.业务员, zhandianBH, "", "");
            DataTable glkdt = glkbll.SelectYS_JX_GUANLIKsDynamic(" I_JLZT=0 and (S_ZHANDIAN='" + zhandianBH + "' or '00'='" + zhandianBH + "' or "+this.LAIHANLCZT+">4)", " S_ZHanDIan");

            C_GuanLiK.DataSource = glkdt;
            C_GuanLiK.TextField = "S_GUANLIKMC";
            C_GuanLiK.ValueField = "S_GUANLIKH";
            C_GuanLiK.DataBind();
            C_GuanLiK.Items.Insert(0,new ListEditItem(" ",""));
            C_GuanLiK.SelectedIndex = 0;
            if (glkdt != null && glkdt.Rows.Count > 0)
            {
                HiddenList.Set("h_glk", glkdt.Rows[0]["S_GUANLIKH"].ToString());

                BindGV();
            }
            HiddenList.Set("laianlcbh",LAIHANLCZT);
            if (LAIHANLCZT == 30)
            {
                UCLHSuggestYiJians.LoadSuggestYiJians(LAIHANLCZT);
            }
            else
            {
                YWYKJYJ.Visible = false;
            }
        }
        /// <summary>
        /// 绑定左侧gridview
        /// </summary>
        private void BindGV()
        { 
            string whereCase = " ";
            if (h_zhandian.Value.Trim().Length == 0 )
            {
                return;
            }
            string roleid = BLL.BusinessTool.GetTextAndValue(
                      "View_AS_UserInfo", "ROLEID", "ROLEID", null, "userid=" + LoginInfo.CurrentUser.UserID
                  ).Tables[0].Rows[0]["VALUE"].ToString();
            bool IsNeedZHANDIAN = false;
            if (roleid != "9001" && roleid != "3001" && roleid != "4001")
            {
                IsNeedZHANDIAN = true;
            }
            if (h_zhandian.Value.Trim().Length >0&&h_zhandian.Value.Trim()!="00"&&!IsNeedZHANDIAN)
            {
                whereCase += " and a.S_ZHANDIANBH='"+h_zhandian.Value+"'";
            }
            bool glk = true;
            if (!string.IsNullOrEmpty(Request["ID"]) && ViewState["IsFirst"] == null)
            {
                glk = false;
                ViewState["IsFirst"] = 1;
            }
            if (HiddenList.Contains("h_glk") &&HiddenList.Get("h_glk")!=null&& HiddenList.Get("h_glk").ToString().Trim().Length > 0 &&  glk&&C_GuanLiK.SelectedIndex>0)
            {
                whereCase += string.Format(" and a.s_guanlikbh='{0}'", HiddenList.Get("h_glk").ToString());
            }
            whereCase += string.Format(" and I_LIUCHENGZT=0 and a.I_LIUCHENGBH={0}", this.LAIHANLCZT);
            whereCase += string.Format(" and i_laihanlx={0}",3);
            if (txtLaiHanBH.Text.Trim().Length > 0)
            {
                whereCase += string.Format(" and a.S_LAIHANBH='{0}'",txtLaiHanBH.Text);
            }
            if (txtYongHuH.Text.Trim().Length > 0)
            {
                whereCase += string.Format(" and a.S_YONGHUBH='{0}'", txtYongHuH.Text);
            }

            if (Table_YeWuY.Visible)
            { 
                
                if (C_YwWuY.SelectedIndex > 0)
                {
                    whereCase += " and S_YEWUY="+C_YwWuY.Value;
                }
            }
            if (roleid == "9001")
            {
                whereCase += " and S_YEWUY=" + LoginInfo.CurrentUser.UserID;
            }
            SetCheckList(0);
            DataSet ds = _sphelper.P_YS_LH_LAIHANCX_WHERE(whereCase);
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0)
            {
                HiddenList.Set("laihanid", ds.Tables[0].Rows[0]["ID"].ToString());
                
            }
            else
            {
                HiddenList.Set("laihanid","");
            }

            gvLH.DataSource = ds.Tables[0];
            gvLH.DataBind();
            
            if (gvLH.VisibleRowCount > 0)
            {
                gvLH.FocusedRowIndex = 0;
                BindUserInfo();
                SetGVFocuseIndex();
            }
            else
            {
                ClearControlValue();
            }
            if (gvLH.VisibleRowCount > FocusIndexGV && FocusIndexGV > -1)
            {
                HiddenList.Set("laihanid", ds.Tables[0].Rows[FocusIndexGV]["ID"].ToString());
                gvLH.FocusedRowIndex = FocusIndexGV;
                BindUserInfo();
            }
            SetCheckList(1);
        }
        /// <summary>
        /// 记录选中行号以及设置选中行
        /// </summary>
        /// <param name="type"></param>
        private void SetCheckList(int type)
        {

            if (type == 0)
            {

                string ids = "";
                for (int i = 0; i < gvLH.VisibleRowCount; i++)
                {
                    CheckBox ck = (CheckBox)gvLH.FindRowCellTemplateControl(i, (GridViewDataColumn)gvLH.Columns[0], "cid");

                    if (ck.Checked)
                    {
                        HiddenField hid = (HiddenField)gvLH.FindRowCellTemplateControl(i, (GridViewDataColumn)gvLH.Columns[0], "id");
                        ids += hid.Value + ",";
                    }
                }
                HiddenList.Set("CheckListValues", ids);
            }
            else
            {

                string ids = HiddenList.Contains("CheckListValues") ? HiddenList.Get("CheckListValues").ToString() : "";
                string[] arrids = ids.Split(',');
                for (int i = 0; i < gvLH.VisibleRowCount; i++)
                {
                    CheckBox ck = (CheckBox)gvLH.FindRowCellTemplateControl(i, (GridViewDataColumn)gvLH.Columns[0], "cid");
                    HiddenField hid = (HiddenField)gvLH.FindRowCellTemplateControl(i, (GridViewDataColumn)gvLH.Columns[0], "id");

                    if (arrids.Contains<string>(hid.Value))
                    {
                        ck.Checked = true;
                    }
                }
            }
        }
        private void SetGVFocuseIndex()
        {
            int vid = 0;
            if (!int.TryParse(Request["ID"], out vid))
            {
                return;
            }
            bool istrue = false;
            for (int i = 0; i < gvLH.VisibleRowCount; i++)
            {
                HiddenField hid = (HiddenField)gvLH.FindRowCellTemplateControl(i, (GridViewDataColumn)gvLH.Columns[0], "id");


                if (Convert.ToInt32(hid.Value) == vid)
                {
                    gvLH.FocusedRowIndex = i;
                    istrue = true;
                    break;
                }
            }
            HiddenList.Set("laihanid", vid);
            if (gvLH.VisibleRowCount>0&&!istrue)
            {
                HiddenField hid = (HiddenField)gvLH.FindRowCellTemplateControl(0, (GridViewDataColumn)gvLH.Columns[0], "id");
                gvLH.FocusedRowIndex = 0;
                HiddenList.Set("laihanid", hid.Value);
            }
            BindUserInfo();
        }
        /// <summary>
        /// 绑定右侧信息
        /// </summary>
        private void BindUserInfo()
        {
            if (HiddenList.Get("laihanid").ToString().Trim().Length == 0)
            {
                return;
            }
            //获得来函信息主表数据
            string where = string.Format(" ID={0} ", HiddenList.Get("laihanid").ToString());
            DataTable LaiHanxx = bllLaiHanxx.SelectYS_LH_LAIHANXXesDynamic(where,"",null);

            if (LaiHanxx == null||LaiHanxx.Rows.Count==0)
            {
                return;
            }
            HiddenList.Set("laihanbh", LaiHanxx.Rows[0]["S_LAIHANBH"]);
            HiddenList.Set("Y", LaiHanxx.Rows[0]["I_Y"]);
            txtLY.Text = LaiHanxx.Rows[0]["S_ShenQIngLY"].ToString();

            txtXingZhengXKSLBH.Text = LaiHanxx.Rows[0]["S_XuKeBH"].ToString();
            txtTongYiSPBH.Text = LaiHanxx.Rows[0]["S_TongyiBM"].ToString();
            //获取受理日期等
            string laihanbh = LaiHanxx.Rows[0]["S_LAIHANBH"].ToString();
            int laihanlx = Convert.ToInt32(LaiHanxx.Rows[0]["I_LAIHANLX"].ToString());
            DataRow drTemp = new SpHelper().P_YS_LHGETINFODETAIL(laihanbh, laihanlx).Tables[0].Rows[0];
            txtShouLiRQ.Text = drTemp["D_SHOULIRQ"] == DBNull.Value ? "" : Convert.ToDateTime(drTemp["D_SHOULIRQ"]).ToString("yyyy-MM-dd");

            //获得转移计划信息
            where = string.Format(" S_LAIHANBH='{0}' and S_YONGHUBHJ='{1}' and i_jlzt=0 and I_LIUCHENGBH=1", LaiHanxx.Rows[0]["S_LAIHANBH"], LaiHanxx.Rows[0]["S_YONGHUBH"]);
            DataTable ZhuanYiJHdt = bllJiHuanZYxx.SelectYS_LH_JIHUAZiesDynamic(where, "", null);
            if (ZhuanYiJHdt == null || ZhuanYiJHdt.Rows.Count == 0)
            {
                return;
            }
            //获得转移计划信息
            where = string.Format(" S_LAIHANBH='{0}' and S_YONGHUBHJ='{1}' and i_jlzt=0 and I_LIUCHENGBH={2} ", LaiHanxx.Rows[0]["S_LAIHANBH"], LaiHanxx.Rows[0]["S_YONGHUBH"], this.LAIHANLCZT);
            DataTable ZhuanYiJHdtNow = bllJiHuanZYxx.SelectYS_LH_JIHUAZiesDynamic(where, "", null);
            ClearShuRuK();
            bool isDefault=true;
            if (ZhuanYiJHdtNow != null && ZhuanYiJHdtNow.Rows.Count > 0)
            {
                txtLiuChengYJ.Text = ZhuanYiJHdtNow.Rows[0]["S_SHENPIYJ"].ToString();
                if (txtLiuChengYJ.Text.Trim().Length > 0)
                {
                    string Mlist = ZhuanYiJHdtNow.Rows[0]["I_M1"] + ",";
                    Mlist += ZhuanYiJHdtNow.Rows[0]["I_M2"] + ",";
                    Mlist += ZhuanYiJHdtNow.Rows[0]["I_M3"] + ",";
                    Mlist += ZhuanYiJHdtNow.Rows[0]["I_M4"] + ",";
                    Mlist += ZhuanYiJHdtNow.Rows[0]["I_M5"] + ",";

                    Mlist += ZhuanYiJHdtNow.Rows[0]["I_M6"] + ",";
                    Mlist += ZhuanYiJHdtNow.Rows[0]["I_M7"] + ",";
                    Mlist += ZhuanYiJHdtNow.Rows[0]["I_M8"] + ",";
                    Mlist += ZhuanYiJHdtNow.Rows[0]["I_M9"] + ",";
                    Mlist += ZhuanYiJHdtNow.Rows[0]["I_M10"] + ",";

                    Mlist += ZhuanYiJHdtNow.Rows[0]["I_M11"] + ",";
                    Mlist += ZhuanYiJHdtNow.Rows[0]["I_M12"];
                    SetShuRuValue(Mlist.Split(','));
                    isDefault = false;
                }
                else
                {
                    ClearShuRuK();
                }
            }
            else
            {
                ClearShuRuK();
            }
            
            txtYeWuYYJ_XS.Text = ZhuanYiJHdt.Rows[0]["S_SHENPIYJ"].ToString();
            ///获得用户信息
            DataTable userdt = bllyhxx.SelectYS_YG_YONGHUXXesDynamic(string.Format(" S_YONGHUH='{0}' and I_LEIXING=0 and i_jlzt=0", LaiHanxx.Rows[0]["S_YONGHUBH"]), "", null);
            if (userdt != null && userdt.Rows.Count > 0)
            {
             
                DataTable user = BusinessTool.GetTextAndValue("view_as_userinfo", "UserID", "UserName", null, string.Format("UserID={0} ", userdt.Rows[0]["S_YEWUY"])).Tables[0];

                txtYeWuY.Text = user.Rows[0]["Value"].ToString();
            }
            ///获得流程信息
            DataTable lcxx = lcbll.SelectYS_LH_LAIHANLCJLsDynamic(string.Format(" S_LAIHANBH='{0}' and I_LIUCHENGBH={1} ", LaiHanxx.Rows[0]["S_LAIHANBH"].ToString(), 2), "", null);
            if (lcxx != null && lcxx.Rows.Count > 0)
            {
                txtShouLiRQ.Text = Convert.ToDateTime(lcxx.Rows[0]["D_StartDate"]).ToString("yyyy-MM-dd");

            }
            ///获得来函用户（甲）信息
            where = string.Format(" S_YONGHUBH='{0}' and i_jlzt=0 ", ZhuanYiJHdt.Rows[0]["S_YONGHUBHJ"]);
            DataTable UserdtJia = bllLaiHanYHXX.SelectYS_LH_YONGHUXXesDynamic(where,"",null);

            if (UserdtJia == null || UserdtJia.Rows.Count == 0)
            {
                return;
            }
            
            txtZhuanChuYHH.Text = UserdtJia.Rows[0]["S_YONGHUBH"].ToString();
            txtZhuanChuYHM.Text =  UserdtJia.Rows[0]["S_YONGHUM"].ToString();
            ///转入用户信息
            where = string.Format(" S_YONGHUBH='{0}' and i_jlzt=0 ", ZhuanYiJHdt.Rows[0]["S_YONGHUBHY"]);
            DataTable UserdtYi = bllLaiHanYHXX.SelectYS_LH_YONGHUXXesDynamic(where, "", null);
            if (UserdtYi == null || UserdtYi.Rows.Count == 0)
            {
                return;
            }
            txtZhuanRuYHH.Text = UserdtYi.Rows[0]["S_YONGHUBH"].ToString();
            txtZhuanRuYHM.Text = UserdtYi.Rows[0]["S_YONGHUM"].ToString();
            ///计划信息
            string  zhandian =BusinessTool.ZHANDIANBH();
            if(this.LAIHANLCZT>4)
            {
                zhandian="00";
            }
            DataSet jhxx = _sphelper.P_YS_LH_JIHUAZY_CX(ZhuanYiJHdt.Rows[0]["S_YONGHUBHJ"].ToString(), ZhuanYiJHdt.Rows[0]["S_YONGHUBHY"].ToString(), Convert.ToInt32(ZhuanYiJHdt.Rows[0]["I_Y"]),zhandian);
            DataTable dt = jhxx.Tables[0];

            HiddenList.Set("ZHANDIAN", ZhuanYiJHdt.Rows[0]["S_ZHANDIANBH"]);
            HiddenList.Set("YHHJ", ZhuanYiJHdt.Rows[0]["S_YONGHUBHJ"]);
            HiddenList.Set("YHHY", ZhuanYiJHdt.Rows[0]["S_YONGHUBHY"]);
            DataTable newdt = dt.Clone();
            if (dt != null && dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    if (Convert.ToInt32(dr["I_LIUCHENGBH"]) == 30)
                    {
                        txtYeWuYYJ_XS.Text = dr["S_SHENPIYJ"].ToString();
                    }
                    else if (Convert.ToInt32(dr["I_LIUCHENGBH"]) == 40)
                    {
                        txtZhuRenYJ_XS.Text = dr["S_SHENPIYJ"].ToString();
                    }
                    else if (Convert.ToInt32(dr["I_LIUCHENGBH"]) == 50)
                    {
                        txtJieShuiKZYJ_XS.Text = dr["S_SHENPIYJ"].ToString();
                    }
                    else if (Convert.ToInt32(dr["I_LIUCHENGBH"]) == 60)
                    {
                        txtJiCcaiKZYJ_XS.Text = dr["S_SHENPIYJ"].ToString();
                    }
                    else if (Convert.ToInt32(dr["I_LIUCHENGBH"]) == 70)
                    {
                        txtChuZhangYJ_XS.Text = dr["S_SHENPIYJ"].ToString();
                    }
                    else if (Convert.ToInt32(dr["I_LIUCHENGBH"]) == -2)
                    {
                        string YuanJiHList = dr["I_M1"].ToString() + ',' + dr["I_M2"] + ',' + dr["I_M3"] + ',' + dr["I_M4"] + ',' + dr["I_M5"]
                                                 + ',' + dr["I_M6"] + ',' + dr["I_M7"] + ',' + dr["I_M8"] + ',' + dr["I_M9"] + ',' + dr["I_M10"]
                                                 + ',' + dr["I_M11"] + ',' + dr["I_M12"];
                        HiddenList.Set("YuanJiHua",YuanJiHList);
                    }

                    if (Convert.ToInt32(dr["I_LIUCHENGBH"]) == this.LAIHANLCZT)
                    {
                        
                    }
                    else
                    {
                        DataRow newdr = newdt.NewRow();
                        foreach (DataColumn d in dt.Columns)
                        {
                            newdr[d.ColumnName] = dr[d.ColumnName];
                        }
                        newdt.Rows.Add(newdr);
                    }
                    
                }
                
            }
            newdt.DefaultView.Sort = " orderby ";
            Repeater1.DataSource = newdt;
            Repeater1.DataBind();
            
            HiddenList.Set("NowYear", ZhuanYiJHdt.Rows[0]["I_Y"]);
            SetButtonStatus(true);
            SetStatusBytxt(false);
            if (isDefault&&LAIHANLCZT>(int)eLaiHanLCBH.业务员)
            {
                SetTextValueByData(LaiHanxx.Rows[0]["S_LAIHANBH"].ToString(), LaiHanxx.Rows[0]["S_YONGHUBH"].ToString());
            }
            if (LAIHANLCZT == 30)
            {
                txtLY.ReadOnly = false;
            }
        }
        private void SetTextValueByData(string laihanbh,string yonghuh)
        {
            string where = "";
            where = string.Format(" S_LAIHANBH='{0}' and S_YONGHUBHJ='{1}' and i_jlzt=0 and I_LIUCHENGBH={2} ", laihanbh,yonghuh, this.LAIHANLCZT > 30 ? LAIHANLCZT - 10 : LAIHANLCZT);
            DataTable ZhuanYiJHdtNow = bllJiHuanZYxx.SelectYS_LH_JIHUAZiesDynamic(where, "", null);

            if (ZhuanYiJHdtNow != null && ZhuanYiJHdtNow.Rows.Count > 0)
            {


                txtLiuChengYJ.Text = "拟同意，报批。";
                if (LAIHANLCZT == (int)eLaiHanLCBH.处长)
                {
                    txtLiuChengYJ.Text = "同意";
                }
                string Mlist = ZhuanYiJHdtNow.Rows[0]["I_M1"] + ",";
                Mlist += ZhuanYiJHdtNow.Rows[0]["I_M2"] + ",";
                Mlist += ZhuanYiJHdtNow.Rows[0]["I_M3"] + ",";
                Mlist += ZhuanYiJHdtNow.Rows[0]["I_M4"] + ",";
                Mlist += ZhuanYiJHdtNow.Rows[0]["I_M5"] + ",";

                Mlist += ZhuanYiJHdtNow.Rows[0]["I_M6"] + ",";
                Mlist += ZhuanYiJHdtNow.Rows[0]["I_M7"] + ",";
                Mlist += ZhuanYiJHdtNow.Rows[0]["I_M8"] + ",";
                Mlist += ZhuanYiJHdtNow.Rows[0]["I_M9"] + ",";
                Mlist += ZhuanYiJHdtNow.Rows[0]["I_M10"] + ",";

                Mlist += ZhuanYiJHdtNow.Rows[0]["I_M11"] + ",";
                Mlist += ZhuanYiJHdtNow.Rows[0]["I_M12"];
                SetShuRuValue(Mlist.Split(','));
            }
        }
        /// <summary>
        /// 设置输入框信息
        /// </summary>
        /// <param name="values"></param>
        private void SetShuRuValue(string [] values)
        {
            txtZYJH1.Text = values[0];
            txtZYJH2.Text = values[1];
            txtZYJH3.Text = values[2];
            txtZYJH4.Text = values[3];
            txtZYJH5.Text = values[4];

            txtZYJH6.Text = values[5];
            txtZYJH7.Text = values[6];
            txtZYJH8.Text = values[7];
            txtZYJH9.Text = values[8];
            txtZYJH10.Text = values[9];

            txtZYJH11.Text = values[10];
            txtZYJH12.Text = values[11];
            txtZYJH13.Text = (Convert.ToInt32(values[0]) + Convert.ToInt32(values[1]) + Convert.ToInt32(values[2])
                + Convert.ToInt32(values[3]) + Convert.ToInt32(values[4]) +
                Convert.ToInt32(values[5]) + Convert.ToInt32(values[6])
                + Convert.ToInt32(values[7]) + Convert.ToInt32(values[8]) 
                + Convert.ToInt32(values[9]) + Convert.ToInt32(values[10])
                + Convert.ToInt32(values[11])).ToString();

            
        }
        /// <summary>
        /// 修改按钮
        /// </summary>
        /// <param name="status"></param>
        private void XIUGAIBtn(bool status)
        {
            SetStatusBytxt(status);
            if (LAIHANLCZT == 30)
            {
                txtLY.ReadOnly = !status;
            }
        }
        private void ClearShuRuK()
        {
            txtZYJH1.Text = "";
            txtZYJH2.Text = "";
            txtZYJH3.Text = "";
            txtZYJH4.Text = "";
            txtZYJH5.Text = "";

            txtZYJH6.Text = "";
            txtZYJH7.Text = "";
            txtZYJH8.Text = "";
            txtZYJH9.Text = "";
            txtZYJH10.Text = "";

            txtZYJH11.Text = "";
            txtZYJH12.Text = "";
            txtZYJH13.Text = "";
            txtLiuChengYJ.Text = "";
        }
        /// <summary>
        /// 无数据清空原始值
        /// </summary>
        private void ClearControlValue()
        {
            txtZhuanRuYHH.Text = "";
            txtZhuanRuYHM.Text = "";

            txtZhuanChuYHH.Text = "";
            txtZhuanChuYHM.Text = "";
            txtXingZhengXKSLBH.Text = "";
            txtTongYiSPBH.Text = "";
            ClearShuRuK();
            txtZhuRenYJ_XS.Text = "";
            txtJieShuiKZYJ_XS.Text = "";
            txtJiCcaiKZYJ_XS.Text = "";
            txtYeWuYYJ_XS.Text = "";
            txtLY.Text = "";
            txtYeWuY.Text = "";
            txtShouLiRQ.Text = "";
            
            DataSet jhxx = _sphelper.P_YS_LH_JIHUAZY_CX(null, null, null, null);
            Repeater1.DataSource = jhxx.Tables[0];
            Repeater1.DataBind();

            SetButtonStatus(false);
        }
        /// <summary>
        /// 设置按钮状态
        /// </summary>
        /// <param name="b"></param>
        private void SetButtonStatus(bool b)
        {
            BtnQR.Enabled = b;
            BtnXG.Enabled = b;
            BtnTJ.Enabled = b;

            BtnXXXX.Enabled = b;
            BtnYSSF.Enabled = b;
            BtnWJLB.Enabled = b;
           
        }
        /// <summary>
        /// 根据流程状态显示指定内容
        /// </summary>
        private void SetDisplay()
        {
            switch (this.LAIHANLCZT)
            { 
                case 30:
                    Table_YeWuY.Visible = false;
                    Div_YiJian.Visible = false;
                    DIV_YeWuYYJ.Visible = false;
                    break;
                case 40:
                    Div_YiJian.Visible = false;
                    break;
                case 50:
                    td_JieShui.Visible = false;
                    td_JieShuitxt.Visible = false;
                    td_JiCaitxt.Visible = false;
                    td_JiCai.Visible = false;
                    td_ChuZhangtxt.Visible = false;
                    td_ChuZhang.Visible = false;
                    break;
                case 60:
                    td_JiCaitxt.Visible = false;
                    td_JiCai.Visible = false;
                    CK_FuShenXG.Visible = true;
                    td_ChuZhangtxt.Visible = false;
                    td_ChuZhang.Visible = false;
                    break;
                case 70 :
                    td_ChuZhangtxt.Visible = false;
                    td_ChuZhang.Visible = false;
                    break;
            }
        }
        /// <summary>
        /// 根据内容设置输入框状态
        /// </summary>
        private void SetStatusBytxt(bool b)
        {
            if (!b)
            {
                txtZYJH1.ClientEnabled = txtZYJH1.Text.Trim().Length == 0;
                txtZYJH2.ClientEnabled = txtZYJH2.Text.Trim().Length == 0;
                txtZYJH3.ClientEnabled = txtZYJH3.Text.Trim().Length == 0;
                txtZYJH4.ClientEnabled = txtZYJH4.Text.Trim().Length == 0;
                txtZYJH5.ClientEnabled = txtZYJH5.Text.Trim().Length == 0;

                txtZYJH6.ClientEnabled = txtZYJH6.Text.Trim().Length == 0;
                txtZYJH7.ClientEnabled = txtZYJH7.Text.Trim().Length == 0;
                txtZYJH8.ClientEnabled = txtZYJH8.Text.Trim().Length == 0;
                txtZYJH9.ClientEnabled = txtZYJH9.Text.Trim().Length == 0;
                txtZYJH10.ClientEnabled = txtZYJH10.Text.Trim().Length == 0;

                txtZYJH11.ClientEnabled = txtZYJH11.Text.Trim().Length == 0;
                txtZYJH12.ClientEnabled = txtZYJH12.Text.Trim().Length == 0;
                //txtZYJH13.Enabled = txtZYJH13.Text.Trim().Length > 0;
                txtLiuChengYJ.ClientEnabled = txtLiuChengYJ.Text.Trim().Length == 0;
            }
            else
            {

                txtZYJH1.ClientEnabled = b;
                txtZYJH2.ClientEnabled = b;
                txtZYJH3.ClientEnabled = b;
                txtZYJH4.ClientEnabled = b;
                txtZYJH5.ClientEnabled = b;

                txtZYJH6.ClientEnabled = b;
                txtZYJH7.ClientEnabled = b;
                txtZYJH8.ClientEnabled = b;
                txtZYJH9.ClientEnabled = b;
                txtZYJH10.ClientEnabled = b;

                txtZYJH11.ClientEnabled = b;
                txtZYJH12.ClientEnabled = b;
                //txtZYJH13.Enabled =b;
                txtLiuChengYJ.ClientEnabled = b;
            }
            SetControlStatus(Convert.ToInt32(HiddenList.Get("NowYear")));
        }

        /// <summary>
        /// 判断原计划输入是否正确
        /// </summary>
        /// <returns></returns>
        private bool CheckJiHuanXX()
        {
            bool b = true;
            if (HiddenList.Contains("YuanJiHua"))
            {
                string[] list = HiddenList.Get("YuanJiHua").ToString().Split(',');
                if (Convert.ToInt32(list[0]) < Convert.ToInt32(txtZYJH1.Text))
                {
                    return false;
                }
                if (Convert.ToInt32(list[1]) < Convert.ToInt32(txtZYJH2.Text))
                {
                    return false;
                }
                if (Convert.ToInt32(list[2]) < Convert.ToInt32(txtZYJH3.Text))
                {
                    return false;
                }
                if (Convert.ToInt32(list[3]) < Convert.ToInt32(txtZYJH4.Text))
                {
                    return false;
                }
                if (Convert.ToInt32(list[4]) < Convert.ToInt32(txtZYJH5.Text))
                {
                    return false;
                }

                if (Convert.ToInt32(list[5]) < Convert.ToInt32(txtZYJH6.Text))
                {
                    return false;
                }
                if (Convert.ToInt32(list[6]) < Convert.ToInt32(txtZYJH7.Text))
                {
                    return false;
                }
                if (Convert.ToInt32(list[7]) < Convert.ToInt32(txtZYJH8.Text))
                {
                    return false;
                }
                if (Convert.ToInt32(list[8]) < Convert.ToInt32(txtZYJH9.Text))
                {
                    return false;
                }
                if (Convert.ToInt32(list[9]) < Convert.ToInt32(txtZYJH10.Text))
                {
                    return false;
                }

                if (Convert.ToInt32(list[10]) < Convert.ToInt32(txtZYJH11.Text))
                {
                    return false;
                }
                if (Convert.ToInt32(list[11]) < Convert.ToInt32(txtZYJH12.Text))
                {
                    return false;
                }

            }
            else
            {
                return false;
            }
            return b;
        }
        private void SetControlStatus(int y)
        {
            int waterYM = BusinessTool.GetWaterYM();
            int month = Convert.ToInt32(waterYM.ToString().Substring(4, 2));
            int iy = Convert.ToInt32(waterYM.ToString().Substring(0, 4));
            if (iy == y)
            {
                switch (month)
                {
                    case 1:
                        PageTools.SetDisabled(txtZYJH1, true);
                       
                        txtZYJH1.Text = "0";
                        txtZYJH2.Focus();
                        break;
                    case 2:
                       PageTools.SetDisabled(txtZYJH1, true);
                        PageTools.SetDisabled(txtZYJH2, true);
                      
                        txtZYJH3.Focus();
                        txtZYJH1.Text = "0";
                        txtZYJH2.Text = "0";
                        break;
                    case 3:
                       PageTools.SetDisabled(txtZYJH1, true);
                        PageTools.SetDisabled(txtZYJH2, true);
                        PageTools.SetDisabled(txtZYJH3, true);

                        txtZYJH4.Focus();
                        txtZYJH1.Text = "0";
                        txtZYJH2.Text = "0";
                        txtZYJH3.Text = "0";

                        break;
                    case 4:
                       PageTools.SetDisabled(txtZYJH1, true);
                        PageTools.SetDisabled(txtZYJH2, true);
                        PageTools.SetDisabled(txtZYJH3, true);
                        PageTools.SetDisabled(txtZYJH4, true);

                        txtZYJH5.Focus();
                        txtZYJH1.Text = "0";
                        txtZYJH2.Text = "0";
                        txtZYJH3.Text = "0";
                        txtZYJH4.Text = "0";

                        break;
                    case 5:
                       PageTools.SetDisabled(txtZYJH1, true);
                        PageTools.SetDisabled(txtZYJH2, true);
                        PageTools.SetDisabled(txtZYJH3, true);
                        PageTools.SetDisabled(txtZYJH4, true);
                        PageTools.SetDisabled(txtZYJH5, true);

                        txtZYJH6.Focus();
                        txtZYJH1.Text = "0";
                        txtZYJH2.Text = "0";
                        txtZYJH3.Text = "0";
                        txtZYJH4.Text = "0";

                        txtZYJH5.Text = "0";

                        break;
                    case 6:
                       PageTools.SetDisabled(txtZYJH1, true);
                        PageTools.SetDisabled(txtZYJH2, true);
                        PageTools.SetDisabled(txtZYJH3, true);
                        PageTools.SetDisabled(txtZYJH4, true);
                        PageTools.SetDisabled(txtZYJH5, true);

                        PageTools.SetDisabled(txtZYJH6, true);

                        txtZYJH7.Focus();
                        txtZYJH1.Text = "0";
                        txtZYJH2.Text = "0";
                        txtZYJH3.Text = "0";
                        txtZYJH4.Text = "0";

                        txtZYJH5.Text = "0";
                        txtZYJH6.Text = "0";

                        break;
                    case 7:
                        PageTools.SetDisabled(txtZYJH1, true);
                        PageTools.SetDisabled(txtZYJH2, true);
                        PageTools.SetDisabled(txtZYJH3, true);
                        PageTools.SetDisabled(txtZYJH4, true);
                        PageTools.SetDisabled(txtZYJH5, true);

                        PageTools.SetDisabled(txtZYJH6, true);
                        PageTools.SetDisabled(txtZYJH7, true);

                        txtZYJH8.Focus();
                        txtZYJH1.Text = "0";
                        txtZYJH2.Text = "0";
                        txtZYJH3.Text = "0";
                        txtZYJH4.Text = "0";

                        txtZYJH5.Text = "0";
                        txtZYJH6.Text = "0";
                        txtZYJH7.Text = "0";

                        break;
                    case 8:
                       PageTools.SetDisabled(txtZYJH1, true);
                        PageTools.SetDisabled(txtZYJH2, true);
                        PageTools.SetDisabled(txtZYJH3, true);
                        PageTools.SetDisabled(txtZYJH4, true);
                        PageTools.SetDisabled(txtZYJH5, true);

                        PageTools.SetDisabled(txtZYJH6, true);
                        PageTools.SetDisabled(txtZYJH7, true);
                        PageTools.SetDisabled(txtZYJH8, true);

                        txtZYJH9.Focus();
                        txtZYJH1.Text = "0";
                        txtZYJH2.Text = "0";
                        txtZYJH3.Text = "0";
                        txtZYJH4.Text = "0";

                        txtZYJH5.Text = "0";
                        txtZYJH6.Text = "0";
                        txtZYJH7.Text = "0";
                        txtZYJH8.Text = "0";



                        break;
                    case 9:
                       PageTools.SetDisabled(txtZYJH1, true);
                        PageTools.SetDisabled(txtZYJH2, true);
                        PageTools.SetDisabled(txtZYJH3, true);
                        PageTools.SetDisabled(txtZYJH4, true);
                        PageTools.SetDisabled(txtZYJH5, true);

                        PageTools.SetDisabled(txtZYJH6, true);
                        PageTools.SetDisabled(txtZYJH7, true);
                        PageTools.SetDisabled(txtZYJH8, true);
                        PageTools.SetDisabled(txtZYJH9, true);


                        txtZYJH10.Focus();
                        txtZYJH1.Text = "0";
                        txtZYJH2.Text = "0";
                        txtZYJH3.Text = "0";
                        txtZYJH4.Text = "0";

                        txtZYJH5.Text = "0";
                        txtZYJH6.Text = "0";
                        txtZYJH7.Text = "0";
                        txtZYJH8.Text = "0";

                        txtZYJH9.Text = "0";


                        break;
                    case 10:
                        PageTools.SetDisabled(txtZYJH1, true);
                        PageTools.SetDisabled(txtZYJH2, true);
                        PageTools.SetDisabled(txtZYJH3, true);
                        PageTools.SetDisabled(txtZYJH4, true);
                        PageTools.SetDisabled(txtZYJH5, true);

                        PageTools.SetDisabled(txtZYJH6, true);
                        PageTools.SetDisabled(txtZYJH7, true);
                        PageTools.SetDisabled(txtZYJH8, true);
                        PageTools.SetDisabled(txtZYJH9, true);
                        PageTools.SetDisabled(txtZYJH10, true);


                        txtZYJH11.Focus();
                        txtZYJH1.Text = "0";
                        txtZYJH2.Text = "0";
                        txtZYJH3.Text = "0";
                        txtZYJH4.Text = "0";

                        txtZYJH5.Text = "0";
                        txtZYJH6.Text = "0";
                        txtZYJH7.Text = "0";
                        txtZYJH8.Text = "0";

                        txtZYJH9.Text = "0";
                        txtZYJH10.Text = "0";


                        break;
                    case 11:
                        PageTools.SetDisabled(txtZYJH1, true);
                        PageTools.SetDisabled(txtZYJH2, true);
                        PageTools.SetDisabled(txtZYJH3, true);
                        PageTools.SetDisabled(txtZYJH4, true);
                        PageTools.SetDisabled(txtZYJH5, true);

                        PageTools.SetDisabled(txtZYJH6, true);
                        PageTools.SetDisabled(txtZYJH7, true);
                        PageTools.SetDisabled(txtZYJH8, true);
                        PageTools.SetDisabled(txtZYJH9, true);
                        PageTools.SetDisabled(txtZYJH10, true);

                        PageTools.SetDisabled(txtZYJH11, true);


                        txtZYJH12.Focus();
                        txtZYJH1.Text = "0";
                        txtZYJH2.Text = "0";
                        txtZYJH3.Text = "0";
                        txtZYJH4.Text = "0";

                        txtZYJH5.Text = "0";
                        txtZYJH6.Text = "0";
                        txtZYJH7.Text = "0";
                        txtZYJH8.Text = "0";

                        txtZYJH9.Text = "0";
                        txtZYJH10.Text = "0";
                        txtZYJH11.Text = "0";

                        break;
                    case 12:
                      
                        PageTools.SetDisabled(txtZYJH1, true);
                        PageTools.SetDisabled(txtZYJH2, true);
                        PageTools.SetDisabled(txtZYJH3, true);
                        PageTools.SetDisabled(txtZYJH4, true);
                        PageTools.SetDisabled(txtZYJH5, true);

                        PageTools.SetDisabled(txtZYJH6, true);
                        PageTools.SetDisabled(txtZYJH7, true);
                        PageTools.SetDisabled(txtZYJH8, true);
                        PageTools.SetDisabled(txtZYJH9, true);
                        PageTools.SetDisabled(txtZYJH10, true);

                        PageTools.SetDisabled(txtZYJH11, true);
                        PageTools.SetDisabled(txtZYJH12, true);


                        txtZYJH1.Text = "0";
                        txtZYJH2.Text = "0";
                        txtZYJH3.Text = "0";
                        txtZYJH4.Text = "0";

                        txtZYJH5.Text = "0";
                        txtZYJH6.Text = "0";
                        txtZYJH7.Text = "0";
                        txtZYJH8.Text = "0";

                        txtZYJH9.Text = "0";
                        txtZYJH10.Text = "0";
                        txtZYJH11.Text = "0";
                        txtZYJH12.Text = "0";
                        break;
                }
            }
        }
        #endregion

    }
}